home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 010 / mstrmind.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1985-04-15  |  7.9 KB  |  217 lines

  1. 10  REM *** mastermind game - by Kevin Burke 11/06/83
  2. 20  REM ***
  3. 30  REM *** Modified 3-26-84 to not use background picture file
  4. 40  REM ***
  5. 50  REM *** note: color values used are as follows: 0-blue
  6. 60  REM ***                                         1-green
  7. 70  REM ***                                         2-red
  8. 80  REM ***                                         3-yellow
  9. 90  REM ***
  10. 100  KEY OFF:SCREEN 0:WIDTH 80:CLS:COLOR 2,0:RANDOMIZE TIMER
  11. 110  AX=180:AY=122:REM                    *** arrow start coordinates
  12. 120  PX=179:PY=122:REM                   *** indicators start coordinates
  13. 130  X=143:Y=122:REM                     *** pointer start coordinates ***
  14. 140  COUNT =2:REM                        *** Will be one after first move ***
  15. 150  GOSUB 370:REM                       *** go and setup everything
  16. 160  TE=75:GOSUB 890:REM                 *** put pointer on first square ***
  17. 170  REM ***
  18. 180  REM *** start of human guesser routine***
  19. 190  REM ***
  20. 200  GOSUB 790 REM                      ***Blink arrow ***
  21. 210  IN$=INKEY$:IF IN$="" THEN GOTO 200
  22. 220  IF LEN(IN$)>1 THEN GOTO 300
  23. 230  IF IN$="B" OR IN$="b" THEN PAINT(X,Y),0,3:TE=77:GOTO 320
  24. 240  IF IN$="R" OR IN$="r" THEN PAINT(X,Y),2,3:TE=77:GOTO 320
  25. 250  IF IN$="G" OR IN$="g" THEN PAINT(X,Y),1,3:TE=77:GOTO 320
  26. 260  IF IN$="Y" OR IN$="y" THEN PAINT(X,Y),3,3:TE=77:GOTO 320
  27. 270  IF IN$="E" OR IN$="e" THEN PAINT(X,Y),0,0:CIRCLE(X,Y),3,3,,,1
  28. 280  IF IN$="A" OR IN$="a" THEN NOARROW=NOT NOARROW
  29. 290  GOTO 200
  30. 300  TE$=MID$(IN$,2,1):REM               *** get the extended key code***
  31. 310  TE=ASC(TE$)
  32. 320  IF TE=77 AND X < 163 THEN GOSUB 890:REM *** move pointer ***
  33. 330  IF TE=75 AND X > 133 THEN GOSUB 890
  34. 340  IF TE=79 THEN GOSUB 1140:REM       *** Go think of response and reset
  35. 350  REM                                         mute-arrow flag.***
  36. 360  GOTO 200
  37. 370  REM ***
  38. 380  REM *** see if he wants instructions
  39. 390  REM ***
  40. 400  LOCATE 1,14:PRINT "Mastermind - Adapted for IBM-PC 11/10/83 By Kevin A. Burke":PRINT:PRINT:PRINT"Would you like to see the instructions? (Y/N)";
  41. 410  COMPUTER=0
  42. 420  A$=INKEY$:IF A$="" THEN GOTO 420
  43. 430  IF A$="Y" OR A$="y" THEN GOSUB 1600
  44. 440  REM ***
  45. 450  REM *** Now put up the board
  46. 460  REM ***
  47. 470  CLS:SCREEN 1,0:COLOR 1,0:LINE (122,15)-(205,165),3,B
  48. 480  LINE (174,15)-(174,165),3
  49. 490  FOR LOOPER = 0 TO 10
  50. 500      LINE (174,127-(LOOPER*10))-(205,127-(LOOPER*10)),3
  51. 510  NEXT LOOPER
  52. 520  LINE (122,137)-(174,137),3
  53. 530  FOR LOOPER = 0 TO 10
  54. 540     FOR INNERLOOPER = 0 TO 3
  55. 550        XTEMP = 163-(INNERLOOPER*10)
  56. 560        YTEMP = 122-(LOOPER*10)
  57. 570        CIRCLE(XTEMP,YTEMP),3,3,,,1
  58. 580     NEXT INNERLOOPER
  59. 590  NEXT LOOPER
  60. 600  REM ***
  61. 610  REM *** computer setup here.
  62. 620  REM ***
  63. 630  IF COMPUTER=2 THEN GOTO 740:REM            *** leave if human is to setup
  64. 640  ANSBLUE=0:ANSGREEN=0:ANSRED=0:ANSYELLOW=0
  65. 650  FOR D=1 TO 4
  66. 660      ANSWER(D)=INT(RND*4):REM               *** set up the row to guess
  67. 670  ON ANSWER(D)+1 GOTO 680,690,700,710
  68. 680  ANSBLUE=ANSBLUE+1:GOTO 720:REM             *** these counter used for
  69. 690  ANSGREEN=ANSGREEN+1:GOTO 720:REM              deciding what indicators
  70. 700  ANSRED=ANSRED+1:GOTO 720:REM                  should be put up.
  71. 710  ANSYELLOW=ANSYELLOW+1
  72. 720  NEXT
  73. 730  PAINT(122,152),0,3:REM                     *** make sure solution is blank
  74. 740  REM ***
  75. 750  REM *** the human setup part will go here.
  76. 760  REM ***
  77. 770  RETURN:REM                                 *** go back to play area
  78. 780  REM ***
  79. 790  REM *** blink the arrow at the correct row
  80. 800  REM ***
  81. 810  IF NOARROW THEN RETURN:REM                 ***Player has requested no                                                         marker arrow
  82. 820  LINE (AX,AY)-(AX+8,AY),1
  83. 830  LINE (AX-3,AY)-(AX,AY-3),1
  84. 840  LINE(AX-3,AY)-(AX,AY+3),1
  85. 850  FOR DELAY=1 TO 100:NEXT
  86. 860  PAINT (AX,AY),0,3
  87. 870  FOR DELAY =1 TO 100:NEXT
  88. 880  RETURN
  89. 890  REM ***
  90. 900  REM *** move the pointer to new location
  91. 910  REM ***
  92. 920  IF TE=66 THEN GOTO 950:REM                        *** REDRAW POINTER ***
  93. 930  IF TE=75 THEN X=X-10:COUNT=COUNT-1
  94. 940  IF TE=77 THEN X=X+10:COUNT=COUNT+1
  95. 950  LOCATE 19,23,0:DEF SEG:POKE &H4E,1:PRINT COUNT;
  96. 960  RETURN
  97. 970  REM ***
  98. 980  REM *** put up the solution
  99. 990  REM ***
  100. 1000  X1=133:Y1=152
  101. 1010  FOR D=1 TO 4
  102. 1020      CIRCLE(X1,Y1),3,3,,,1
  103. 1030     ON ANSWER(D)+1 GOSUB 1070,1080,1090,1100
  104. 1040     X1=X1+10
  105. 1050  NEXT D
  106. 1060  RETURN
  107. 1070  PAINT (X1,Y1),0,3:RETURN
  108. 1080  PAINT (X1,Y1),1,3:RETURN
  109. 1090  PAINT (X1,Y1),2,3:RETURN
  110. 1100  PAINT (X1,Y1),3,3:RETURN
  111. 1110  REM
  112. 1120  REM *** Scan the guess row and fill in the count block for decision
  113. 1130  REM
  114. 1140  LOCATE 19,23,0:PRINT"  ";:LOCATE 25,17,0:DEF SEG:POKE &H4E,2:PRINT"Thinking";
  115. 1150  FOR D=0 TO 3
  116. 1160    GUESS(D+1)=POINT(133+(10*D),Y)
  117. 1170  NEXT D
  118. 1180  REM ***
  119. 1190  REM *** now start parsing (right word??) the array
  120. 1200  REM ***
  121. 1210  BLUEGUESS=0:REDGUESS=0:YELLOWGUESS=0:GREENGUESS=0
  122. 1220  FOR D=1 TO 4
  123. 1230    IF ANSWER(D)=GUESS(D) THEN HIT=HIT+1:CLOS=CLOS-1
  124. 1240    ON GUESS(D)+1 GOTO 1250,1260,1270,1280
  125. 1250    BLUEGUESS=BLUEGUESS+1:GOTO 1290
  126. 1260    GREENGUESS=GREENGUESS+1:GOTO 1290
  127. 1270    REDGUESS=REDGUESS+1:GOTO 1290
  128. 1280    YELLOWGUESS=YELLOWGUESS+1
  129. 1290  NEXT D
  130. 1300  REM
  131. 1310  REM *** now look through and see how many colors right he got **
  132. 1320  REM
  133. 1330  IF ANSBLUE > 0 THEN IF BLUEGUESS > 0 THEN IF BLUEGUESS>ANSBLUE THEN                CLOS=CLOS+ANSBLUE ELSE CLOS=CLOS+BLUEGUESS
  134. 1340  IF ANSGREEN > 0 THEN IF GREENGUESS > 0 THEN IF GREENGUESS>ANSGREEN THEN            CLOS=CLOS+ANSGREEN ELSE CLOS=CLOS+GREENGUESS
  135. 1350  IF ANSRED > 0 THEN IF REDGUESS > 0 THEN IF REDGUESS>ANSRED THEN                    CLOS=CLOS+ANSRED ELSE CLOS=CLOS+REDGUESS
  136. 1360  IF ANSYELLOW>0 THEN IF YELLOWGUESS>0 THEN IF YELLOWGUESS>ANSYELLOW THEN            CLOS=CLOS+ANSYELLOW ELSE CLOS=CLOS+YELLOWGUESS
  137. 1370  REM ***
  138. 1380  REM *** put the indicators up on the screen
  139. 1390  REM ***
  140. 1400  FOR D=1 TO HIT
  141. 1410    CIRCLE(PX,PY),2,1,,,1
  142. 1420    PAINT(PX,PY),1,1
  143. 1430    PX=PX+7
  144. 1440  NEXT D
  145. 1450  FOR D=1 TO CLOS
  146. 1460    CIRCLE(PX,PY),2,2,,,1
  147. 1470    PAINT(PX,PY),2,2
  148. 1480    PX=PX+7
  149. 1490  NEXT D
  150. 1500  REM ***
  151. 1510  REM *** see if he won or whether he ran out of guesses ***
  152. 1520  REM ***
  153. 1530  IF HIT=4 THEN GOSUB 1880
  154. 1540  IF Y<32 THEN GOSUB 2090
  155. 1550  REM ***
  156. 1560  REM *** Update pointers/prompts
  157. 1570  REM ***
  158. 1580  COUNT=2:PX=179:PY=PY-10:AY=AY-10:X=143:Y=Y-10:HIT=0:CLOS=0
  159. 1590  LOCATE 25,1,0:PRINT STRING$(38," ");:GOTO 160
  160. 1600  REM ***
  161. 1610  REM *** instructions
  162. 1620  REM
  163. 1630  CLS:SCREEN 0,0:COLOR 2,0
  164. 1640  PRINT:PRINT TAB(35)"Mastermind"
  165. 1650  PRINT:PRINT"    This is the computer version of the popular board game, Mastermind."
  166. 1660  PRINT"The computer will think up colors,";
  167. 1670  PRINT" (";:COLOR 12,0:PRINT"Red/";:COLOR 14,0:PRINT"Yellow/";:COLOR 10,0:PRINT"Green/";:COLOR 9,0:PRINT"Blue";:COLOR 2,0:PRINT")";:PRINT" for a row":PRINT"comprised of four pieces, each with possibly (probably) a different color."
  168. 1680  PRINT"    You try and match the pattern the computer has chosen. To do this"
  169. 1690  PRINT"you have 10 chances. Each turn, you lay down the colors in a pattern of"
  170. 1700  PRINT"your choice. The way the computer will let you know how close you are"
  171. 1710  PRINT"getting is in two types of markers he can place. These markers"
  172. 1720  PRINT"(or indicators) will be found in the rows on the far right side of"
  173. 1730  PRINT"the board. you will be given a ";:COLOR 10,0:PRINT"GREEN";:COLOR 2,0:PRINT" marker for each piece that is"
  174. 1740  PRINT"the right color AND in the right place on the board. You will be"
  175. 1750  PRINT"given a ";:COLOR 12,0:PRINT"RED";:COLOR 2,0:PRINT" piece for each piece that is the right color BUT the"
  176. 1760  PRINT"wrong position on the board. Keep guessing until you (A) guess"
  177. 1770  PRINT"the correct pattern, or (B) run out of chances."
  178. 1780  PRINT"    The number in the bottom right half of the board is to tell you "
  179. 1790  PRINT"which piece in the row your invisible cursor is on. To turn that"
  180. 1800  PRINT"square into the color you choose, just hit the first letter of that"
  181. 1810  PRINT"color (i.e. R,G,B,Y) the arrow keys will let you move back and"
  182. 1820  PRINT"forth. If you change your mind, just back up and type the New"
  183. 1830  PRINT"colors letter. EXCEPT if color to be changed is yellow hit 'E' first."
  184. 1840  PRINT"    The flashing arrow on the right tells you which row you are working on."
  185. 1850  PRINT "If you dont like the flashing arrow, then hit the letter 'A' to remove it."
  186. 1860  COLOR 22,0:LOCATE 25,1,0:PRINT TAB(30)"Hit any key to continue";
  187. 1870  IF INKEY$="" THEN GOTO 1870 ELSE RETURN
  188. 1880  REM ***
  189. 1890  REM *** put up solution and pat him on the back
  190. 1900  REM ***
  191. 1910  GOSUB 970
  192. 1920  LOCATE 25,14:DEF SEG:POKE &H4E,3
  193. 1930  PRINT"CONGRATULATIONS!!";
  194. 1940  FOR X=1 TO 2
  195. 1950     FOR Y=1 TO 200
  196. 1960         COLOR Y,0
  197. 1970     NEXT Y
  198. 1980  NEXT X
  199. 1990  COLOR 1,0
  200. 2000  FOR LOOP = 1 TO 3
  201. 2010     LOCATE 25,14:DEF SEG:POKE &H4E,3
  202. 2020     PRINT"CONGRATULATIONS!!";
  203. 2030     FOR DELAY=1 TO 300:NEXT DELAY
  204. 2040     LOCATE 25,14:PRINT"                   ";
  205. 2050     FOR DELAY=1 TO 300:NEXT DELAY
  206. 2060  NEXT LOOP
  207. 2070  LOCATE 25,14,0:PRINT "Play again (y/n)?";
  208. 2080  A$=INKEY$:IF A$="" THEN GOTO 2080 ELSE IF A$="y" OR A$="Y" THEN RUN ELSE CLS:SCREEN 0:WIDTH 80:COLOR 2,0:PRINT"thanks for playing!!":END
  209. 2090  GOSUB 970
  210. 2100  FOR LOOP= 1 TO 6
  211. 2110  LOCATE 25,17,0:PRINT "Too Bad!!!";
  212. 2120  FOR DELAY =1 TO 400:NEXT
  213. 2130  LOCATE 25,16,0:PRINT "              ";
  214. 2140  FOR DELAY =1 TO 400:NEXT
  215. 2150  NEXT LOOP
  216. 2160  GOTO 2070
  217.